package read.niit.dao

import read.niit.common.TGradeBookDao
import read.niit.util.JDBCUtil

class GradeBookDao extends TGradeBookDao{

  override def insertGradeBook(grade_id: String, count: Int): Unit = {
    // 1.获得Mysql连接
    val conn = JDBCUtil.getConnection
    // 2.编写并执行Mysql语句，以及传递参数
    JDBCUtil.executeUpdate(conn,
      """
        |INSERT INTO
        |       gradeBookTable(grade_id,count)
        |VALUES(?,?)
        |ON DUPLICATE KEY UPDATE
        |  count = count + ?
        |""".stripMargin,Array(grade_id,count,count))
    // 3.关闭连接
    conn.close()
  }

}
